package 
{
	import constants.Events;
	import flash.display.Sprite;
	import flash.events.Event;
	import logics.EventDispatch;
	import logics.GameField;
	import logics.StateMachine;
	import logics.UnitFactory;
	import logics.CustomEvent;
	import structures.Struct1;
	import structures.Struct2;
	import structures.Struct3;
	import structures.Struct4;
	import vessels.DrawVessel;
	import vessels.Vessel;
	import vessels.Vessel1;
	import vessels.Vessel2;
	
	import points.CollidePoint;
	
	/**
	 * ...
	 * @author parasitic
	 */
	
	
	public class Main extends Sprite 
	{
		private var machine:StateMachine;
		private var dispatch:EventDispatch;
		private var field:GameField;
		private var factory:UnitFactory;
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			//add logic instances
			{
				machine = new StateMachine();
				dispatch = new EventDispatch(machine);
				field = new GameField(machine);
				factory = new UnitFactory(machine);
			}
			
			//pass logic instances to stage
			{
				stage.addChild(machine);
				stage.addChild(dispatch);
				stage.addChild(field);
				stage.addChild(factory);
				dispatchEvent(new CustomEvent(Events.SET_FREE));
			}
				
			//add struct types to factory
			{
				factory.addType(Struct1);
				factory.addType(Struct2);
				factory.addType(Struct3);
				factory.addType(Struct4);
			}
			
			var a:Vessel = new Vessel2();
			var b:Vessel = new Vessel1();
			
			b.set_x(100);
			b.set_y(100);
			a.set_x(200);
			a.set_x(200);
			addChild(b);
			addChild(a);
			
			b.rotateTarget(a);
			
		}
		
	}
	
}